// 对象的深拷贝
function cloneDeepObj(obj) {
  // 浅拷贝子节点
  const handleChild = (child) => {
    if (typeof child === 'object') {
      if (Array.isArray(child)) { // 数组
        return [...child]
      } else if (child) { // 对象
        return { ...child }
      } else { // null
        return child
      }
    } else { // 值类型
      return child
    }
  }

  const arr = []
  const target = { result: obj }
  let current = target
  let temp = null
  if (typeof current === 'object') {
    if (Array.isArray(current)) { // 数组
      current.forEach((item, index) => {
        const child = handleChild(item)
        current[index] = child
        arr.push(child)
      })
    } else if (current) { // 对象
      const objKeys = Object.keys(current)
      objKeys.forEach(key => {
        const child = handleChild(current[key])
        current[key] = child
        arr.push(child)
      })
    } else { // null
      temp = current
    }
  }
  current = arr.shift()
  return target.result
}
